#include<stdio.h>
int total,arr[1000000];
void process(long n){
    int i;
    total=0;
    while(n>1){
        i=9;
        while(n%i!=0 && i>1)i--;
        if(i==1){
            total=0;
            return;
        }
        arr[++total]=i;
        n/=i;
    }
}
int main(){
    long m,i,n;
    FILE *fpinp=fopen("G2.IN","r");
    FILE *fpout=fopen("G2.OUT","w");
    fscanf(fpinp,"%ld",&m);
    for(i=1;i<=m;i++){
        
        fscanf(fpinp,"%ld",&n);
        process(n);
        
        if(i!=1)fprintf(fpout,"\n");
        if(total==0)fprintf(fpout,"0");
        else for(;total>=1;total--)fprintf(fpout,"%d",arr[total]);
    }
    fclose(fpinp);
    fclose(fpout);
    return 0;
}
